package centerberg.game;

import centerberg.engine.Drawable;
import centerberg.engine.Engine;
import centerberg.engine.PhysicsObject;
import centerberg.engine.Solid;
import centerberg.engine.Texture;

import java.awt.Shape;
import java.awt.geom.Rectangle2D;
import java.util.Map;

/**
 * Solid walls. Is a separate class from {@link Ground}
 * since we should not be allowed to jump along the walls.
 * 
 * @author Andreas Svanberg
 */
public class Wall extends Solid implements Drawable
{
    private Texture texture;
    
    private Wall(Shape shape, Texture texture)
    {
        super(shape);
        this.texture = texture;
    }
    
    /**
     * {@inheritDoc}. Does nothing since walls are static.
     */
    public void collided(PhysicsObject other)
    {
    }
    
    /**
     * Creates a new wall object with the given attributes.
     * Used by the loader to create them based on XML-data.
     * 
     * @param attributes a map determining how to create
     *                   the walls
     */
    public static Wall create(Map<String, String> attributes)
    {
        int x = Integer.parseInt(attributes.get("x"));
        int h = Integer.parseInt(attributes.get("height"));
        
        Shape shape = new Rectangle2D.Double(x, 0, 800, h);
        Texture texture = Engine.getInstance().resourceManager.textures
                .getTiledTexture(attributes.get("texture"), 800, h);
        
        texture.translate(x, 0);
        
        Wall wall = new Wall(shape, texture);
        return wall;
    }
    
    /**
     * {@inheritDoc}
     */
    public Texture getTexture()
    {
        return texture;
    }
    
    /**
     * {@inheritDoc}. Does nothing since walls are static.
     */
    public void tick(double elapsed)
    {
    }
    
    /**
     * {@inheritDoc}. Does nothing since walls are static.
     */
    public void translated(double dx, double dy)
    {
    }
}